<?php
class UserModel extends Model{
	public $table = 'user';
	public function validate_login(){
		if( Q('post.code',NULL,'strtoupper') != session('code')){
            $this->error='验证码错误';
            return false;
		}
		$username=Q('post.username');
		$password=Q('post.password',NULL);
		$userInfo=$this->where(array('username'=>$username))->find();
		
		if(!$userInfo){
			$this->error='用户名不存在';
			return false;
		}
		if($password!=$userInfo['password']){
			$this->error='密码不正确';
			return false;			
		}
		return $userInfo;
	}
	public function add_data($data){
		return $this->add($data);
	}
	public function get_data($where=NULL){
		return $this->where($where)->all();
	}
	public function dele($where=NULL){
		return $this->where($where)->delete();
	}
	public function change_lock(){
		$stat = Q('post.stat', 0, 'intval');
		$uid = Q('post.uid', 0, 'intval');
        if($stat){
        	$this->where(array('uid'=>$uid))->update(array('is_lock'=>0));
        }else{
        	$this->where(array('uid'=>$uid))->update(array('is_lock'=>1));
        }
	}
}